Field of the Invention
The present invention relates to an image encoding apparatus, an image encoding method, and a program, and more particularly, to a technique of adaptively controlling an amount of code for an image.
Description of the Related Art
H.264/MPEG-4 AVC (hereinafter referred to as H.264) is known as a coding method for use in encoding a moving image into a compressed form (ITU-TH.264 (03/2010), Advanced video coding for generic audio visual services). In H.264, an image is encoded in units of blocks. In the encoding, a quantization parameter used in quantizing the image is variable from one block to another.
In a technique disclosed in International Publication No. WO 02/080574, encoding is controlled based on an index value indicating complexity or smoothness of an image to be compressed such that high image quality is achieved in a region in which an image is monotonous and smooth and thus image quality degradation due to compression is easily visually perceptible (hereinafter, such a region will be referred to as a flat region). Furthermore, in the technique disclosed in International Publication No. WO 02/080574 the encoding is controlled such that the image quality is reduced for a region in which image is complex (hereinafter, such a region will be referred to as a non-flat region). The complexity of an image is evaluated based on a difference between luminance of each pixel in a block of interest and the mean value of luminance taken over the block. In the technique disclosed in International Publication No. WO 02/080574, the image quality is optimized by adaptively controlling the image quality in the above-described manner.
Furthermore, in the technique disclosed in International Publication No. WO 02/080574, each block is divided into sub-blocks, and an index value for the judgment on the flat region is determined for each of the sub-blocks thereby making it possible to detect a flat region even in a case where the block includes both a flat region and a non-flat region.
Referring to FIG. 6, controlling the image quality based on the flat region judgment according to the technique disclosed in International Publication No. WO 02/080574 is described below. FIG. 6 illustrates an image including a black object in a white background, in which squares represented by solid lines denote blocks each including 16×16 pixels. Reference numeral 601 denotes one of blocks (white blocks) in the white background. All pixels in this block have a similar large pixel value, and thus the complexity of this block is low. Reference numeral 603 denotes one of blocks (black blocks) of the black object. In this block, all pixels have a small pixel value, and thus the complexity of this block is low. Reference numeral 602 denotes a block located on a boundary between a white block and a black block. The block 602 includes both black and white pixels, and thus there is a large difference between the luminance of each pixel and the mean value of the luminance of the block, and therefore the complexity of this block is high. Therefore, in a case where the judgment of the flat region is performed simply based on the complexity of each block and the quantization parameter is determined based on the result of the judgment, the quantization parameter for blocks with high complexity is set to be large. However, in blocks located on a boundary as with the block 602, image quality degradation is, in general, easily perceptible, and thus it may be desirable to set the quantization parameter to be small.
If each block is divided into a sub-block each including 8×8 pixels as represented by broken lines in FIG. 6, then all pixels in two sub-blocks in the block 602 are black while all pixels in the other two sub-blocks in the block 602 are white. That is, when the complexity is evaluated in units of sub-blocks, the complexity is similar to either that of the block 601 or the block 603. By determining the complexity in units of sub-blocks in the above-described manner, it becomes possible to determine more precisely whether blocks are on a boundary and thus degradation in image quality is easily susceptible, and thus it becomes possible to suppress degradation in image quality that would otherwise occur due to setting the quantization parameter to a large value.
However, in the technique disclosed in International Publication No. WO 02/080574, the index value for detecting flat regions is calculated as many times as there are sub-blocks, which results in an increase in calculation cost. Furthermore, in the technique disclosed in International Publication No. WO 02/080574, any block including a sub-block determined to be a flat region is encoded such that high image quality is obtained, which results in an increase in the number of blocks that are processed so as to obtain high image quality. In this case, encoding flat regions so as to have high image quality results in an increase in the total amount of code, which means that in a case the amount of code is limited, it is difficult to achieve high image quality for flat regions.
In the following, referring to FIG. 11 and FIG. 12, problems with controlling image quality in the technique disclosed in International Publication No. WO 02/080574 are described. In FIG. 11, blocks 1101 to 1107 are arranged according to the complexity determined in units of blocks. Each block is evaluated based on its complexity in terms of whether it is a flat region, and the quantization parameter therefor is determined. FIG. 12 illustrates a result obtained in a case where classifying and determination of the quantization parameter are performed based on the complexity for each of four sub-blocks into which each block is divided. In the case where the complexity is determined in units of sub-blocks, pixels of any sub-block except for sub-blocks in the block 1105 are equal in pixel value within the sub-block, and thus the complexity is low. That is, the number of blocks determined to be a flat region increases, and thus the quantization parameter is set to be low to achieve high image quality in encoding. As a result, the total amount of code increases.